package cn.kgc.mushroomdatabaseprovider.service.serviceimpl;

import cn.kgc.mushroomcommon.pojo.Shoppingcar;
import cn.kgc.mushroomcommon.pojo.ShoppingcarExample;
import cn.kgc.mushroomdatabaseprovider.mapper.ShoppingcarMapper;
import cn.kgc.mushroomdatabaseprovider.service.ShoppingcarService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly = true)
public class ShoppingcarServiceImpl implements ShoppingcarService {
    @Resource
    ShoppingcarMapper shoppingCarMapper;

    @Override
    public List<Shoppingcar> selectShoppingCarList() {
        return shoppingCarMapper.selectByView();
    }


    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)    @Override
    public int batchRemove(List<Integer> shoppingCarIdList) {
        ShoppingcarExample shoppingCarExample = new ShoppingcarExample();

        shoppingCarExample.createCriteria().andIdIn(shoppingCarIdList);

        int i = shoppingCarMapper.deleteByExample(shoppingCarExample);
        return i;
    }

    @Override
    public List<Shoppingcar> getShoppingCarListByIdList(List<Integer> shoppingCarIdList) {
        ShoppingcarExample shoppingCarExample = new ShoppingcarExample();

        shoppingCarExample.createCriteria().andIdIn(shoppingCarIdList);

        // 执行查询
        return shoppingCarMapper.getShoppingCarListByIdList(shoppingCarExample);
    }
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    @Override
    public int addShopCar(Shoppingcar shoppingcar) {
        return shoppingCarMapper.insert(shoppingcar);
    }
}
